<!--XOA DON HANG-->
<?php
if (isset($_GET['remove']))
{
    $donhangid = $_GET ['donhangid'];
    $result = mysql_query("DELETE FROM donhang where donhangid = $donhangid; ");
    if ($result)
        print '<h2>Xóa thành công !</h2>';
}
?>

<!--DOI TRANG THAI-->
<?php
if (isset($_GET['trangthai']))
{
    $trangthai = $_GET ['trangthai'];
    $donhang = $_GET ['donhang'];
    
    //echo $trangthai;
    $result=mysql_query("select * from donhang where donhangid=$donhang ");
    while ($row = mysql_fetch_array($result))
        {
            if ("$row[tinhtrang]" == 8) 
                $result2 = mysql_query("update donhang set tinhtrang = 1 where donhangid=$donhang;");
            if ("$row[tinhtrang]" == 1)
                $result2 = mysql_query("update donhang set tinhtrang = 2 where donhangid=$donhang;");
            if ("$row[tinhtrang]" == 2)
                $result2 = mysql_query("update donhang set tinhtrang = 8 where donhangid=$donhang;");
//            if ($result2)
//                    print '<script>Thành công !</h2>';
        }
}
?>



<!--HIEN THI THONG TIN DON HANG-->
<h1>Quản lý đơn hàng</h1>
<form action="index.php?quanlybanhang&module=quanlydonhang&page=1" method="get" enctype="multipart/form-data">

Hiển thị đơn hàng theo :

<!--loc theo trang thai-->         
<select name="tinhtrang" id="tinhtrang" disabled="disabled">
    <option value="0">Trạng thái</option>
    <option value="8">Cần xem lại</option>
    <option value="1">Chờ xét duyệt</option>
    <option value="2">Đã gửi sản xuất</option>
    <option value="3">Đang sản xuất</option>
    <option value="4">Đã giao hàng</option>             
</select>


<!--loc theo thanh vien, chi danh cho quan ly-->
<?php
if (!isset($_GET['banhang']))
{
 ?>  
<select name="thanhvien" id="thanhvien">
                        <option value="0" > thành viên </option>
                        <?php $loop = mysql_query("select * from thanhvien where phongban=9");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        if ("$row[thanhvienid]" == $_GET['thanhvien'])
                                        {
                                            print "<option value=$row[thanhvienid] selected='selected' >$row[tenthanhvien]</option>";    
                                        }
                                        else    print "<option value=$row[thanhvienid] >$row[tenthanhvien]</option>";
                                    }
                                    
                        ?></select>
<?php } ?>

<!--loc theo tinh chat-->
<select name="tinhchat" id="tinhchat">
            <option value="0">tính chất</option>
            <?php $loop = mysql_query("select * from tinhchatdonhang");
                    while ($row = mysql_fetch_array($loop))
                        {
                            if ("$row[tinhchatid]" == $_GET['tinhchat'])
                                        {
                                            print "<option value=$row[tinhchatid] selected='selected' >$row[loaitinhchat]</option>";    
                                        }
                                        else    print "<option value=$row[tinhchatid] >$row[loaitinhchat]</option>";
                        }   
            ?></select>
             
<!--loc theo thoi gian-->         
<select name="thang" id="thang">
    <option value="0">các tháng</option>
    <?php 
        for ($i=1; $i<13; $i++)
            if ("$i" == $_GET['thang'])
            {
                    print "<option value='$i' selected='selected'>Tháng $i</option>";
            }
            else    print "<option value='$i'>Tháng $i</option>";
     ?> 
</select>

            
<!--loc theo tinh thanh-->         
<select disabled="1" name="tinh" id="tinh">
    <option value="0">tỉnh thành</option>
            <?php $loop = mysql_query("select * from tinhthanh");
                    while ($row = mysql_fetch_array($loop))
                        print "<option value=$row[tinhthanhid]>$row[tentinhthanh]</option>";
            ?> 
</select>





<input type="hidden" name="quanlybanhang" value="" />
<input type="hidden" name="module" value="quanlydonhang" />
<input type="hidden" name="page" value="1" />


<input type="submit" value="Lọc" /> <br /><br />
</form> 

  <?php
  
  if(isset($_GET['thanhvien']))
      {
        if(isset($_GET['banhang'])){   
            $thanhvienid = $_SESSION['thanhvien'];
            $query = " select * from donhang where thanhvien=$thanhvienid ";}   
        else{
            $query = " select * from donhang where tinhtrang <> 0 ";}
        $tv = " thanhvien = $_GET[thanhvien] ";
        $tc = " tinhchat = $_GET[tinhchat] ";
        $month = " month(ngayki) = $_GET[thang] ";
        $where = " where ";
        $and = " and ";
        
        
        if($_GET['thanhvien'] !=0) 
            {
                if($_GET['tinhchat'] !=0)
                    {
                        if($_GET['thang'] !=0)
                            {
                                $query = $query.$where.$tv.$and.$tc.$and.$month;        //tv,tc,thang    
                            }
                        else    $query = $query.$where.$tv.$and.$tc;                    //tv,tc
                    }
                else
                    {
                        if($_GET['thang'] !=0)
                            {
                                $query = $query.$where.$tv.$and.$month;                 //tv,thang    
                            }
                        else    $query = $query.$where.$tv;                             //tv
                    }
            }
        else
            {
                if($_GET['tinhchat'] !=0)
                    {
                        if($_GET['thang'] !=0)
                        {
                            $query = $query.$where.$tc.$and.$month;                     //tc,thang    
                        }
                        else    $query = $query.$where.$tc;                             //tc                
                    }
                else
                    {
                        if($_GET['thang'] !=0)
                            {
                                $query = $query.$where.$month;                          //thang    
                            }
                        else    $query = $query;                                        //
                    }                                            
            }
            //print "$query";
            
            
            $quanlydonhang = mysql_query($query);
            
            //---DEM SO SAN PHAM TIM DUOC----   
            $numberofresult = mysql_num_rows($quanlydonhang);
            print "Có $numberofresult đơn hàng <br/><br/>";
            
            //---DEM SO TRANG HIEN THI----
            $trang = $numberofresult/10;
            //print $trang;
            if ("$numberofresult" != 0) print "Trang: ";
            for ($sotrang=1; $sotrang<$trang+1; $sotrang++)
                print "<a href='index.php?quanlybanhang&module=quanlydonhang&page=$sotrang&thanhvien=$_GET[thanhvien]&tinhchat=$_GET[tinhchat]&thang=$_GET[thang]'>
                        <input type='button' value='$sotrang'/></a>";
                
            //---HIEN THI 10 SAN PHAM DUA THEO SO TRANG DA CHON----
            if (isset($_GET['page']))
            {
                $page = $_GET['page'];    
            }
            else $page = 1;
            $batdau=$page*10-10;
            $query = $query." order by donhangid DESC limit $batdau,10 ";
            $quanlydonhang = mysql_query($query);   
  }
  if ("$numberofresult" != 0)
  {
?> 
<br /><br />
<table width="780" border='1px' bordercolor='pink' cellspacing='0px' cellpadding='4px' style='border-collapse: collapse;'>
  <tr style='font-weight: bolder; background: none;' height='30px'>
    <th width="10" scope="col">STT</th>
    <th width="200" scope="col">Tên đơn hàng</th>
    <th width="200" scope="col" colspan="3">Thông tin chi tiết</th>
    <th width="67" scope="col">Trạng thái</th>    
  </tr>


        <?php
        } 
            $mau = 0; $stt=0;
            while ($row8 = mysql_fetch_array($quanlydonhang))
            {
            ?>
            
  <tr style='
  <?php 
        if ("$mau" == 0)
        {
            $mau = 1;
            print"background-color: #FFE780;";    
        }
        else $mau = 0;
   ?> 
    '>
    <td class="tieudethongtinao" align="center" ><strong><?php $stt=$stt+1; print "<strong>$stt</strong>" ?></strong></td>
    <td align="left" >
        <table width="250" border="0" cellspacing="0" cellpadding="3" class="thongtinao">
            <tr>
                
                    
<!--TEN, TINH CHAT DON VI LAM AO-->
                <td colspan="2" class="tieudethongtinao" ><strong><?php print "$row8[donvilam]"; ?></strong> <br />
            </tr>
            <tr>
                <td width="100" >
                
            <?php $loop = mysql_query("select * from tinhchatdonhang where tinhchatid=$row8[tinhchat]");
                                    while ($row = mysql_fetch_array($loop))
                                        {
                                                  print "$row[loaitinhchat]";                                
                                        } 
                  $loop = mysql_query("select * from tinhthanh where tinhthanhid=$row8[tinhthanh]");
                    while ($row = mysql_fetch_array($loop))
                        print " - $row[tentinhthanh]";                      
                  ?>
                                     
                </td>
    
<!--THANH VIEN LAM DON-->
                <td width="50">    
                    <?php $loop = mysql_query("select * from thanhvien where thanhvienid=$row8[thanhvien]");
                                    while ($row = mysql_fetch_array($loop))
                                        {
                                                  print "$row[tenthanhvien]";                                
                                        } ?> 
                </td>                        
            </tr>
            <tr>
                <td colspan="2"></td>
            </tr>
            <tr>
                <td colspan="2"><img src="<?php print"$row8[hinhtongquan]" ?>" alt="Ảnh áo" width="250" />
                <a href="<?php print"$row8[filehinhchitiet]" ?>">Link file chi tiết</a>
                </td>
            </tr>
        </table>
</td>
    <td colspan="3">
        
<!--BANG THONG TIN AO--> 
      <table width="200" border="0" cellspacing="0" class="thongtinao" >
        <tr>
          <td colspan="2"><div align="center" class="tieudethongtinao" >
            <div align="center"><strong>Thông tin áo</strong></div>
          </div></td>
          </tr>
        <tr>
          <td width="73"><div align="left"><strong>Số lượng</strong></div></td>
          <td width="111"><div align="left"><?php print "$row8[soluong]"; ?></div></td>
        </tr>
        <?php
            if ("$row8[khuyenmai]" != 0)
                {
        ?> 
        <tr>
          <td><div align="left"><strong>Khuyến mại</strong></div></td>
          <td><div align="left"><?php $khuyenmai = mysql_query("select * from khuyenmai where khuyenmaiid = $row8[khuyenmai]");
                        while ($row10 = mysql_fetch_array($khuyenmai))
                            {
                                print "$row10[tenkhuyenmai]"; 
                            }
                    ?></div></td>
        </tr>
        <?php } ?> 
        <tr>
          <td><div align="left"><strong>Ngày</strong></div></td>
          <td><div align="left">
            <?php $date = "$row8[ngayki]";$d = getdate(strtotime($date));print $d['mday'].'-'.$d['mon'].'-'.$d['year'];?><br />
            <?php $date = "$row8[ngaytra]";$d = getdate(strtotime($date));print $d['mday'].'-'.$d['mon'].'-'.$d['year'];?><br /></div></td>
        </tr>
        <tr>
          <td><div align="left"><strong>Thiết kế</strong></div></td>
          <td><div align="left"><?php
                if ("$row8[designer]" == 0) print "Khách tự thiết kế"; 
                $des = mysql_query("select * from thanhvien where thanhvienid=$row8[designer]");
                                while ($row11 = mysql_fetch_array($des))
                                    {
                                        print "$row11[tenthanhvien]";
                                    }
      
                ?></div></td>
        </tr>
        <tr>
          <td><div align="left"><strong>Mã vải</strong></div></td>
          <td> <div align="left"><?php $loop = mysql_query("select * from vai where vaiid=$row8[mavai]");
                        while ($row = mysql_fetch_array($loop))
                            {
                                      print "$row[mavai] - $row[kieuvai]";                                
                            }
                ?><br />
          </div></td>
        </tr>
        <tr>
          <td><div align="left"><strong>Chi tiết</strong></div></td>
          <td> <div align="left"><?php
                        if ("$row8[kieuco]" == 0 ) print "cổ tròn ";
                        if ("$row8[kieuco]" == 1 ) 
                        {
                            $loop = mysql_query("select * from mau where mauid=$row8[mauco]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "cổ bẻ $row[tenmau], ";                                
                                    }
                            $loop = mysql_query("select * from mau where mauid=$row8[mautrutren]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "trụ trên $row[tenmau], ";                                
                                    }
                            $loop = mysql_query("select * from mau where mauid=$row8[mautruduoi]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "trụ dưới $row[tenmau] <br/> ";                                
                                    }
                        }
                        
                        if ("$row8[comu]" == 1 ) 
                        {
                            $loop = mysql_query("select * from mau where mauid=$row8[maumu]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "có mũ $row[tenmau], ";                                
                                    }
                        }
                        
                        if ("$row8[taykhacmau]" == 1 ) 
                        {
                            $loop = mysql_query("select * from mau where mauid=$row8[mautayao]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "tay áo $row[tenmau], ";                                
                                    }
                        }
                        
                        if ("$row8[intenrieng]" == 1 )  {print "in tên riêng, ";}
                        if ("$row8[aodaitay]" == 1 )  {print "áo dài tay, ";}
                        
                        
                        
                        
                        
                        if ("$row8[chitietthemco]" == 1 ) 
                        {
                            print "cổ ";
                            if ("$row8[chitietthemco]" == 1 ) print "lé ";
                            if ("$row8[chitietthemco]" == 2 ) print "bọc ";
                            
                            $loop = mysql_query("select * from mau where mauid=$row8[mauchitietthemco]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "$row[tenmau], ";                                
                                    }
                        }
                        
                        if ("$row8[chitietthemtay]" == 1 ) 
                        {   
                            print "tay ";
                            if ("$row8[chitietthemtay]" == 1 ) print "lé ";
                            if ("$row8[chitietthemtay]" == 2 ) print "bọc ";
                            if ("$row8[chitietthemtay]" == 2 ) print "can ";
                            
                            $loop = mysql_query("select * from mau where mauid=$row8[mauchitietthemtay]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "$row[tenmau], ";                                
                                    }
                        }
                        
                        if ("$row8[chitietthemgau]" == 1 ) 
                        {
                            print "gấu ";
                            if ("$row8[chitietthemgau]" == 1 ) print "lé ";
                            
                            $loop = mysql_query("select * from mau where mauid=$row8[mauchitietthemgau]");
                                while ($row = mysql_fetch_array($loop))
                                    {
                                        print "$row[tenmau], ";                                
                                    }
                        }
                        
                        
                ?> </div></td>
        </tr>
        <tr>
          <td><div align="left"><strong>Chú ý may</strong></div></td>
          <td><div align="left"><?php print "$row8[chuymay]";  ?></div></td>
        </tr>
        <tr>
          <td><div align="left"><strong>Chú ý in</strong></div></td>
          <td><div align="left"><?php print "$row8[chuyin]";  ?></div></td>
        </tr>
      </table>

<!--BANG THONG TIN KHACH HANG-->
 
      <table width="180" border="0" cellspacing="0" class="thongtinao" >
      <tr>
        <td><div align="center" class="tieudethongtinao" ><strong>Khách hàng</strong></div></td>
      </tr>
      <tr>
              <td>
              <?php $khachhang = mysql_query("select * from khachhang where khachhangid = $row8[khachhang]");
                while ($row9 = mysql_fetch_array($khachhang))
                {
                    print "<img src='styles/customer.png' /> <strong>$row9[tenkhachhang]</strong> - ";
                    if ("$row9[gioitinh]" == 1) print "Nam";
                        else print "Nữ";
                    print "<br /><img src='styles/date.png' />";?> <?php $date = "$row9[ngaysinh]";$d = getdate(strtotime($date));print $d['mday'].'-'.$d['mon'].'-'.$d['year'];?><br />
                    <?php  print "<img src='styles/identity.png' /> $row9[cmt]<br /> 
                            <img src='styles/mobile.png' /> 0$row9[sdt1]<br />
                            <!--<img src='styles/email.png' /> $row9[email]<br /-->
                                ";
                }
                ?>
                </td>
    </tr>
    </table>
    
<!--BANG THONG TIN SIZE AO--> 
    
      <table width="180" border="0" cellspacing="0" class="thongtinao" >
        <tr>
          <td colspan="2"><div align="center" class="tieudethongtinao" ><strong>Size</strong></div></td>
        </tr>
        <tr>
          <td><strong>Nam <?php print "($row8[sizenamtong])"; ?> </strong></td>
          <td><?php if ("$row8[sizenams]" != 0 ) print "$row8[sizenams]S ";
            if ("$row8[sizenamm]" != 0 ) print "$row8[sizenamm]M ";
            if ("$row8[sizenaml]" != 0 ) print "$row8[sizenaml]L ";
            if ("$row8[sizenamxl]" != 0 ) print "$row8[sizenamxl]XL ";
            if ("$row8[sizenamxxl]" != 0 ) print "$row8[sizenamxxl]XXL ";
            if ("$row8[sizenamxxxl]" != 0 ) print "$row8[sizenamxxxl]XXXL ";
            if ("$row8[sizenamxxxxl]" != 0 ) print "$row8[sizenamxxxxl]XXXXL ";
       ?></td>
        </tr>
        <tr>
          <td><strong>Nữ <?php print "($row8[sizenutong])"; ?> </strong></td>
          <td><?php if ("$row8[sizenus]" != 0 ) print "$row8[sizenus]S ";
            if ("$row8[sizenum]" != 0 ) print "$row8[sizenum]M ";
            if ("$row8[sizenul]" != 0 ) print "$row8[sizenul]L ";
            if ("$row8[sizenuxl]" != 0 ) print "$row8[sizenuxl]XL ";
            if ("$row8[sizenuxxl]" != 0 ) print "$row8[sizenuxxl]XXL ";
            if ("$row8[sizenuxxxl]" != 0 ) print "$row8[sizenuxxxl]XXXL ";
            if ("$row8[sizenuxxxxl]" != 0 ) print "$row8[sizenuxxxxl]XXXXL ";                      
       ?></td>
        </tr>
      </table> 
      
<!--BANG THONG TIN THANH TOAN-->       
      
      <table width="180" border="0" cellspacing="0" class="thongtinao" >
        <tr>
          <td colspan="2"><div align="center" class="tieudethongtinao"><strong>Thanh toán</strong></div></td>
        </tr>
        <tr>
          <td><strong>Đơn giá</strong></td>
          <td><?php print "$row8[dongia]"; ?></td>
        </tr>
        <tr>
          <td><strong>Tổng tiền</strong></td>
          <td><?php print "$row8[tongtien]"; ?></td>
        </tr>
        <tr>
          <td height="16"><strong>Đặt trước</strong> </td>
          <td><?php print "$row8[dattruoc]"; ?></td>
        </tr>
        <tr>
          <td><strong>Còn lại</strong> </td>
          <td><?php print "$row8[conlai]"; ?></td>
        </tr>
      </table>        
    
    </td>

<!--TRANG THAI DON HANG--> 

    <td><p>
    <a href="index.php?quanlybanhang&module=quanlydonhang&thanhvien=0&tinhchat=0&thang=0&trangthai&donhang=<?php print "$row8[donhangid]"; ?>"/>
    <?php   //print ("$row8[tinhtrang]");
            if ("$row8[tinhtrang]" == 8) print "<img src='styles/gift.png'> <em>Cần sửa lại</em>";
            if ("$row8[tinhtrang]" == 1) print "<img src='styles/gift.png'> <em>Đang chờ duyệt</em>";
            if ("$row8[tinhtrang]" == 2) print "<em>Đã gửi sản xuất</em>";
            print "</p></a>";
            if ("$row8[tinhtrang]" == 3) print "<em>Đang sản xuất</em>";
            if ("$row8[tinhtrang]" == 4) print "<em>Sản xuất hoàn thành</em>";
    ?></p><br />        
    <p>
<?php if (!isset($_GET['banhang'])){ ?>
    <a href='index.php?quanlybanhang&module=chuy&sales&donhang=<?php print "$row8[donhangid]"; ?>'>
    <img src='styles/gift.png'/> Chú ý với sales</a>
    <br/><a href='index.php?quanlybanhang&module=chuy&sanxuat&donhang=<?php print "$row8[donhangid]"; ?>'>
    <img src='styles/gift.png'/> Chú ý với sản xuất</a>


<?php } else { ?>
    <a href='index.php?quanlybanhang&module=chuy&sales&donhang=<?php print "$row8[donhangid]"; ?>'>
    <img src='styles/gift.png'/> Chú ý với quản lý</a>
<?php } ?> 
</p>
            
                 
    
    <br />
    <br />    
    
<!--neu la SALES, CHI DUOC SUA XOA NEU DANG LUU TAM-->   
<?php if (!isset($_GET['banhang'])){ ?>     
    <!--a href="index.php?quanlybanhang&module=suadonhang&thanhvien=0&tinhchat=0&thang=0&donhangid=<?php print "$row8[donhangid]"; ?>&edit">
            <img src='styles/edit.png'/> Sửa</a>
    -->
    <br/><a href="index.php?quanlybanhang&module=quanlydonhang&thanhvien=0&tinhchat=0&thang=0&donhangid=<?php print "$row8[donhangid]"; ?>&remove" onclick="return confirm('Muốn xóa thật ko?')" >
            <img src='styles/delete.png'/> Xóa</a>
            
<?php } else{   if (("$row8[tinhtrang]" == 0) or ("$row8[tinhtrang]" == 8)) {?>
    <!--a href="index.php?banhang&module=suadonhang&thanhvien=0&tinhchat=0&thang=0&donhangid=<?php print "$row8[donhangid]"; ?>&edit">
            <img src='styles/edit.png'> Sửa</a>
    -->
    <br/><a href="index.php?banhang&module=quanlydonhang&thanhvien=0&tinhchat=0&thang=0&donhangid=<?php print "$row8[donhangid]"; ?>&remove" onclick="return confirm('Muốn xóa thật ko?')" >
            <img src='styles/delete.png'/> Xóa</a>
<?php 
}}
 ?>  
    </td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>

<?php } ?>
</table>